package it.gameplanet.client;

import it.gameplanet.client.utils.AbstractAsyncCallback;
import it.gameplanet.client.widgets.GamePlanetPanel;
import it.gameplanet.client.widgets.UserPanel;
import it.gameplanet.client.widgets.news.NewsPanel;
import it.gameplanet.model.User;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.DecoratedStackPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GamePlanet implements EntryPoint {

	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {

		GamePlanetContext.bootstrap(new AbstractAsyncCallback<User>() {

			@Override
			public void onSuccess(User user) {
				// Add the nameField and sendButton to the RootPanel
				// Use RootPanel.get() to get the entire body element
				DecoratedStackPanel stackPanel = new DecoratedStackPanel();
				stackPanel.setWidth("300px");
				stackPanel.add(GamePlanetContext.getArticoliTree(), "Catalogo" );
				stackPanel.add(new GamePlanetPanel(), "Gameplanet" );
				stackPanel.add(new UserPanel(), "Utenza" );
				
				RootPanel.get("treeContainer").add(stackPanel);

				GamePlanetContext.setHomePage(new NewsPanel());			
				
				Image headerImage = new Image("images/gameplanet.jpg");
				headerImage.addStyleName("gwt-header-image");
				headerImage.addClickHandler(new ClickHandler() {
					
					@Override
					public void onClick(ClickEvent event) {
						GamePlanetContext.resetHomePage();
					}
				});
				RootPanel.get("headerContainer").add(headerImage);
			}
			
		});		
	}

}
